package com.icoolkj.security.springboot.service.impl;

import com.icoolkj.security.springboot.dto.UserDTO;
import com.icoolkj.security.springboot.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author icoolkj
 * @version 1.0
 * @description
 * @createDate 2025/02/07 16:01
 */
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    // 根据账号查询用户信息
    @Override
    public UserDTO getUserByUserName(String username) {
        String sql ="select user_id id, user_name username, password, nick_name fullname, phonenumber mobile  from sys_user where user_name = ?";
        // 连接数据库查询用户
        List<UserDTO> list = jdbcTemplate.query(sql, new Object[]{username}, new BeanPropertyRowMapper<>(UserDTO.class));
        if (list != null && list.size() == 1){
            return list.get(0);
        }
        return null;
    }
}
